<template>
  <el-select
    v-model="selects"
    clearable
    multiple
    :multiple-limit="2"
    filterable
    :placeholder="$language.local('请选择') + $language.local('服务科目')"
    @change="selectChange"
  >
    <el-option
      v-for="item in serviceContents"
      :key="item.id"
      :label="item.name"
      :value="item.id + '#' + item.name"
    >
    </el-option>
  </el-select>
</template>

<script>
export default {
  name: "SelectService",
  props: ["value", "serviceId"],
  data() {
    return {
      selects: [],
      serviceContents: [],
    };
  },
  created() {
    this.selects = this.value;
    if (this.serviceId) {
      this.getInvoiceType();
    }
  },
  watch: {
    value(newValue) {
      this.selects = newValue;
    },
    serviceId(newValue) {
      this.serviceId = newValue;
      this.getInvoiceType();
    },
  },
  methods: {
    async getInvoiceType() {
      let data = {
        typenum: "004",
        sid: this.serviceId,
      };
      console.log(data);
      let response = await this.$http.get(
        "/api/Common/GetdictionaryItem",
        data
      );
      console.log(response);
      this.serviceContents = response.data.Data;
    },
    selectChange(e) {
      this.$emit("input", e);
    },
  },
};
</script>
<style lang="less" scoped>
.el-select {
  width: 100%;
}
</style>
